home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b135.asm < prev    next >
Assembly Source File  |  1992-04-28  |  4KB  |  79 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.35    3-Dimensional Graphics Illumination  
  8. ;Illumination of objects in three dimensions consists of light from  three sources: diffuse lighting from 
  9. ;a point source, ambient light  and specular lighting.  Specular lighting is caused by an object  directly 
  10. ;reflecting the illumination source.  The following variables  describe the illumination process:  
  11. ;L     Direction vector to the point light source L={Lx,Ly,Lz} 
  12. ;N     Direction vector normal to the object N={Nx,Ny,Nz} 
  13. ;Ip    Intensity of the point source 
  14. ;;Kd    Diffuse reflection constant 0<= Kd <= 1.0 
  15. ;Ia    Intensity of ambient light 
  16. ;Ka    Ambient reflection constant 0<= Ka <= 1.0 
  17. ;R     Direction vector of reflection of the point source from the 
  18. ;      object R={Rx,Ry,Rz} 
  19. ;;V     Direction vector from the object to the viewpoint 
  20. ;Ks    Specular reflection constant 0<= Ks <= 1.0 
  21. ;
  22. ;It should be noted that all vectors are normalized to unit magnitude.  
  23. ;The illumination can be described several ways depending on the  complexity of the object and light 
  24. ;source:  
  25. ;I=Ip Kd L*N           Diffuse reflection 
  26. ;I=Ia Ka + Ip Kd L*N   Ambient lighting and diffuse reflection 
  27. ;I=Ia Ka + Ip(Kd L*N + Ks(R*V)**n) 
  28. ;                      Ambient lighting, diffuse reflection and 
  29. ;                      specular reflection (Phong model) 
  30. ;
  31. ;In the above equations, * represents a vector dot product such as  L*N = LxNx+LyNy+LzNz and ** 
  32. ;represents exponentiation.  
  33. ;Since the dot product of two normalized vectors is less than or equal  to one, the term Ks(R*V)**n is 
  34. ;less than one.  The value of this term  is found by using a 256 element lookup table with 256.0(R*V) 
  35. ;as an  index.  The value of n is an arbitrary term that is fixed for the  algorithm and depends on em-
  36. ;pirical conditions.  
  37. ;           X memory                     Y memory  
  38. ;  vec   R0 ?  Rx                  Vx 
  39. ;             Ry                  Vy 
  40. ;             Rz                  Vz 
  41. ;             Lx                  Nx 
  42. ;             Ly                  Ny 
  43. ;             Lz                  Nz 
  44. ;  ktbl  R4? 256.0 
  45. ;             address of spctbl 
  46. ;             Kd 
  47. ;             Ip 
  48. ;             Ia 
  49. ;             Ka 
  50. ;               3-D Graphics Illumination                     Program    ICycles 
  51. ;                                                            Words 
  52.   move                         #vec,r0                 ; 2        2 
  53.   move                         #ktbl,r4                ; 2        2 
  54.   move                         x:(r0)+,d6.s y:,d7.s    ; 1        1 
  55.   fmpy.s d6,d7,d0              x:(r0)+,d6.s y:,d7.s    ; 1        1 
  56.   fmpy.s d6,d7,d1              x:(r0)+,d6.s y:,d7.s    ; 1        1 
  57.   fmpy   d6,d7,d1 fadd.s d1,d0 x:(r0)+,d6.s y:,d7.s    ; 1        1 
  58.   fmpy   d6,d7,d1 fadd.s d1,d0 x:(r4)+,d2.s            ; 1        1 
  59.   fmpy.s d2,d0,d0              x:(r4)+,n1              ; 1        1 
  60.   intrz  d0                    x:(r0)+,d6.s y:,d7.s    ; 1        1 
  61.   fmpy.s d6,d7,d0              d0.l,r1                 ; 1        1 
  62.   move                         x:(r0)+,d6.s y:,d7.s    ; 1        1 
  63.   fmpy   d6,d7,d0 fadd.s d0,d1 x:(r1+n1),d2.s          ; 1        2 
  64.   fadd.s d0,d1                 x:(r4)+,d0.s            ; 1        1 
  65.   fmpy.s d0,d1,d1              x:(r4)+,d0.s            ; 1        1 
  66.   fadd.s d1,d2                 x:(r4)+,d1.s            ; 1        1 
  67.   fmpy.s d2,d0                 x:(r4),d2.s             ; 1        1 
  68.   fmpy.s d1,d2,d1                                      ; 1        1 
  69.   fadd.s d1,d0                                         ; 1        1 
  70.                                                        ;---      --- 
  71.                                             ;   Totals: 20       21 
  72.  
  73. ;The illumination value I is in d0.  
  74. ;Reference: "Fundamentals of Interactive Computer Graphics", 
  75. ;           James D. Foley, Andries Van Dam 
  76. ;           Addison-Wesley 1982 
  77.